<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="fn"  uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page import="kr.co.insoft.framework.config.Authorities" %>
<c:set var="CONTEXT">${pageContext.request.contextPath}</c:set>
<c:set var="cssUrl">${pageContext.request.contextPath}/resources/css</c:set>
<c:set var="jsUrl">${pageContext.request.contextPath}/resources/js</c:set>
<div class="col-sm-12 page-header custom-page-header">
	<h1><spring:message code="menu.configration.cloudvender"/></h1>	
</div>
<form:form modelAttribute="venderEntityModel" role="form" cssClass="form-horizontal">
	<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
	<form:input path="userid" type="hidden"/>
	<input type="hidden" id="chkName" name="chkName" value="N"/>
	<div class="form-group">
		<form:label path="venderName" cssClass="col-sm-2 control-label"><spring:message code="configration.cloud.venderName"/></form:label>
		<div class="col-sm-4"> 
			<form:input path="venderName" cssClass="form-control inputCloudNm"/>
		</div>
		<div class="col-sm-2"> 
			<button class="btn btn-primary btn-sm btnCheckName" type="button" ><spring:message code="common.check.name"/></button>
		</div>
		
	</div>
	
	<div class="form-group">
		<form:label path="typeSeq" cssClass="col-sm-2 control-label"><spring:message code="configration.cloud.supported.list"/></form:label>
		<div class="col-sm-2">			
			<form:select path="typeSeq" items="${venderTypeList }" itemLabel="typeName" itemValue="typeSeq" cssClass="form-control"></form:select>			
		</div>
	</div>
		 
	<div class="form-group">
		<form:label path="venderDesc" cssClass="col-sm-2 control-label"><spring:message code="configration.cloud.venderDesc"/></form:label>
		<div class="col-sm-10"><form:textarea path="venderDesc"  cssClass="form-control"/></div>
	</div>
	
	<div class="form-group">
		<div class="col-sm-12 text-right">
		<button class="btn btn-default btn_link" data-link="./lists" type="button"><spring:message code="button.list"/></button>
		<c:if test="${fn:contains(buttons , Authorities.CREATE)}">
		<button class="btn btn-primary submitBtn" type="button"><spring:message code="button.save"/></button>
		</c:if>		
		</div>
	</div>
</form:form>

<script type="text/javascript"><!--

$(document).on("change", ".inputCloudNm", function(){
	$("input[name='chkName']").val("N");
}).on("click", ".submitBtn", function() {
	bootbox.confirm("<spring:message code='common.save.confirm'/>", function(result) {
		if($("#chkName").val() == 'N'){
			bootbox.alert('이름 중복 체크를 눌러주세요.');
			return;
		}	
		if ( result ) {
			Loading.show();
			$.post("./createForm", $("#venderEntityModel").serialize(), function(res) {
				
			}).fail(function() {
				bootbox.alert("<spring:message code='common.server.fail'/>"); /* 서버 통신 오류 */
			}).done(function(res) {
				if ( res ) {
					bootbox.alert("<spring:message code='common.save.ok'/>", function() {
						Loading.link("./lists");							
					});
				} else {
					bootbox.alert("<spring:message code='common.save.fail'/>");
				}
			}).always(function() {
				Loading.hide();
			});
		}
	});
}).on("click", ".btnCheckName", function() {
	var venderName = $("#venderName").val();
	if(venderName == ""){
		bootbox.alert('Vender 명을 입력해주세요.');
		return;
	}
	$.get("./isExistsVenderName", {"venderName":venderName}, function(res) {		
		if(res){
			bootbox.alert('중복된 이름이 있습니다.');
			$("#venderName").val("");
			$("#venderName").focus();
		}else{
			bootbox.alert('사용 가능한 Vender명입니다.');
			$("input[name='chkName']").val("Y");
		}
	});
});

//--></script>